package com.getpebble.android.framework.util;

import com.getpebble.android.PebbleApplication;
import com.getpebble.android.common.model.FirmwareVersion;
import com.getpebble.android.common.model.LanguagePackModel;
import com.getpebble.android.common.model.PblDeviceModel.PblDeviceRecord;

public class PebbleCapabilities {
    private static final FirmwareVersion APP_AVAILABLE_VIBRATE = new FirmwareVersion("v2.5", 0);
    private static final FirmwareVersion APP_MSG_SUPPORT = new FirmwareVersion("v1.10.0", 0);
    private static final FirmwareVersion HAPPY_MEAL = new FirmwareVersion("v1.8.1", 0);
    private static final FirmwareVersion MULTI_GEN_LOG_STORAGE = new FirmwareVersion("v1.10.0", 0);
    private static final FirmwareVersion NO_EXTENSIBLE_NOTIFICATION_SUPPORT = new FirmwareVersion("v2.8", 0);
    private static final FirmwareVersion NO_LANGUAGE_PACK_SUPPORT = new FirmwareVersion("v2.7", 0);
    private static final FirmwareVersion SPOOLING_SUPPORT = new FirmwareVersion("v2.0", 0);

    public static class ConnectedDevice {
        public static boolean isLanguageSupported() {
            PblDeviceRecord record = PebbleApplication.getConnectedDeviceRecord();
            return record != null && PebbleCapabilities.remoteSupportsLanguagePacks(record.fwVersion);
        }

        public static boolean isInPrf() {
            PblDeviceRecord record = PebbleApplication.getConnectedDeviceRecord();
            return record != null && record.isRunningRecoveryFw;
        }

        public static boolean isVibrateSupported() {
            PblDeviceRecord record = PebbleApplication.getConnectedDeviceRecord();
            return record != null && PebbleCapabilities.remoteSupportsLanguagePacks(record.fwVersion);
        }

        public static int getSupportedLanguagesCount() {
            PblDeviceRecord record = PebbleApplication.getConnectedDeviceRecord();
            if (record == null) {
                return 0;
            }
            return LanguagePackModel.getLanguageCount(PebbleApplication.getAppContext().getContentResolver(), record.fwVersion, record.hwPlatform);
        }
    }

    public static boolean remoteSendsFirmwareUpdateAck(FirmwareVersion remoteVersion) {
        return remoteVersion.compareTo(HAPPY_MEAL) >= 0;
    }

    public static boolean remoteSupportsAppMessage(FirmwareVersion remoteVersion) {
        return remoteVersion.compareTo(APP_MSG_SUPPORT) >= 0;
    }

    public static boolean remoteSupportsSpooling(FirmwareVersion remoteVersion) {
        return remoteVersion.compareTo(SPOOLING_SUPPORT) >= 0;
    }

    public static boolean remoteSupportsExtensibleNotifications(FirmwareVersion remoteVersion) {
        return remoteVersion.compareTo(NO_EXTENSIBLE_NOTIFICATION_SUPPORT) > 0;
    }

    public static boolean remoteSupportsLanguagePacks(FirmwareVersion remoteVersion) {
        return remoteVersion.compareTo(NO_LANGUAGE_PACK_SUPPORT) > 0;
    }
}
